const { defineConfig } = require('@vue/cli-service')
const bodyParser = require('body-parser')
const Mock = require('mockjs')
// 城市数据
// 公司数据

const BossList = Mock.mock({
  'list|50': [
    {
      id: '@id()',
      'title|+1': ['高级前端开发工程师', '前端开发工程师', '前端架构工程师', '前端leader'],
      companyName: '@cname()',
      companyInfo: '@cword(20)',
      jobRequirements: ['3年', 'vue', 'react', 'nodejs', '专科'],
      salary: '@integer(10, 30)',
      address: '@city()',
      recruiterName: '@cname()',
    },
  ],
})

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    setupMiddlewares: (middlewares, { app }) => {
      // 处理post参数
      app.use(bodyParser.json())

      // 登陆
      app.post('/api/list', (req, res) => {
        const { phone } = req.body
        res.json({ code: 0, data: { token: `${phone}_admin` } })
      })

      app.get('/api/job-list', (req, res) => {
        const { page = 1, size = 10 } = req.query
        res.json({ code: 0, data: BossList.list.slice((page - 1) * size, page * size) })
      })

      return middlewares
    },
  },
})
